from playwright.sync_api import expect, Page
from tools.Data import Data
import pytest
import time

# 新增入库单页面
class AddGownPage:

    def __init__(self, page: Page):
        self.data = Data()
        self.page = page
        # 库区
        self.area = "库区1"
        # 库位
        self.location = "库位1"
        # 包装规格
        self.specification = "100"
        # 重量
        self.weight = "20.000"
        # 批次号
        self.batch = self.data.generate_random_number()
        self.batch_no = "0"
        # 姓名
        self.name = self.data.generate_name()
        # 手机号
        self.phone = self.data.generate_phone_number()
        # 身份证
        self.idCard = self.data.generate_id_number()

    # 新增入库
    def navigate(self):
        self.page.goto("/#/instorage/inbound/add")

    # 待入库
    def awaiting_stock_in(self):
        self.page.goto("/#/instorage/inbound/")

    # 入库单信息
    def godown_entry_info(self):
        self.page.get_by_placeholder("请选择客户类型").click()
        self.page.get_by_text("仓储物流").click()
        self.page.get_by_placeholder("请选择公司名称").click()
        self.page.get_by_text("星月科技(小星,13200000009)").click()
        self.page.get_by_placeholder("请选择仓库").click()
        self.page.locator("li").filter(has_text="南城仓").click()

    def goods_entry_info(self):
        self.page.get_by_role("button", name="添加货物").click()
        # 选择品类、品名、厂家、牌号
        self.page.locator("label").filter(has_text="通用塑料").click()
        self.page.locator("span").filter(has=self.page.get_by_placeholder("请选择品类")).click()
        self.page.locator("li").filter(has_text="ABS").click()
        self.page.locator("span").filter(has=self.page.get_by_placeholder("请选择厂家")).click()
        self.page.get_by_text("北京首塑").click()
        self.page.locator("span").filter(has=self.page.get_by_placeholder("请选择牌号")).click()
        self.page.get_by_text("A310", exact=True).click()

        # 入库货物
        self.page.get_by_placeholder("请选择库区").click()
        self.page.get_by_text(self.area).click()
        self.page.get_by_placeholder("请选择库位").click()
        self.page.get_by_text(self.location).click()
        self.page.get_by_placeholder("请选择货物性质").click()
        self.page.locator("li").filter(has_text="代采").click()
        self.page.get_by_placeholder("请选择存储计价类型").click()
        self.page.get_by_text("弹性体").click()
        self.page.get_by_placeholder("请输入包装规格(kg/包)").click()
        self.page.get_by_placeholder("请输入包装规格(kg/包)").fill(self.specification)
        self.page.get_by_placeholder("请输入重量(吨)").click()
        self.page.get_by_placeholder("请输入重量(吨)").fill(self.weight)
        self.page.get_by_placeholder("请输入数量（个/包/桶/板）").click()
        self.page.get_by_placeholder("请选择原料状态").click()
        self.page.locator("li").filter(has_text="固体").click()
        self.page.get_by_placeholder("请输入批次号").click()
        self.page.get_by_placeholder("请输入批次号").fill(self.batch)
        # 获取批次号
        self.batch_no = self.page.get_by_placeholder("请输入批次号").input_value()
        print(self.batch_no)
        self.page.locator("form").filter(has_text="品类 通用塑料工程塑料化工用料改性/再生塑料品类 ABS").get_by_role(
            "button").click()

    def delivery_information(self):
        # 编辑送货信息
        self.page.get_by_placeholder("请输入入库车辆牌号").click()
        self.page.get_by_placeholder("请输入入库车辆牌号").fill("粤B001")
        self.page.get_by_placeholder("请选择送货时间").click()
        self.page.get_by_text("今天").click()
        self.page.get_by_placeholder("请输入司机姓名").click()
        self.page.get_by_placeholder("请输入司机姓名").fill(self.name)
        self.page.get_by_placeholder("请输入司机手机号").click()
        self.page.get_by_placeholder("请输入司机手机号").fill(self.phone)
        self.page.get_by_placeholder("请输入司机身份证号").click()
        self.page.get_by_placeholder("请输入司机身份证号").fill(self.idCard)

        # 是否加班单选按钮,选择"是"
        self.page.locator(".arco-radio-icon").first.click()
        # 是否质检,选择"是"
        self.page.locator("label").filter(has_text="是").nth(3).click()
        # 是否质检,选择"否"
        # self.page.locator("label").filter(has_text="否").nth(3).click()
        # 提交
        self.page.get_by_role("button", name="提交").click()

    def inbound_receipt(self):
        # self.page.wait_for_timeout(3000)
        # 定位表格
        # n = self.page.locator('//*[@class="arco-table-element"]/tbody/tr[1]/td[2]')
        # print(n.inner_text())  # 获取第1行第2列数据,批次号
        # 待入库订单入库
        self.page.locator(".arco-link").first.click()
        self.page.get_by_placeholder("请输入备注").click()
        self.page.get_by_placeholder("请输入备注").fill("自动入库")
        self.page.get_by_role("button", name="提交").click()


















